package com.tsing.bms.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tsing.bms.service.IRepairsService;
import com.tsing.bms.vo.req.*;
import com.tsing.bms.vo.resp.RepairsRespVo;
import com.tsing.common.annotations.SystemLog;
import com.tsing.common.utils.ResultUtil;
import com.tsing.common.vo.ResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author TheTsing
 * @since 2021-03-29
 */
@Api(tags = "报修管理")
@RestController
@RequestMapping("/repairs")
public class RepairsController {

    @Autowired
    private IRepairsService repairsService;

    @PostMapping("/addRepairs")
    @ApiOperation(value = "报修申请")
    @SystemLog(description = "报修申请")
    public ResultData addRepairs(@Validated @RequestBody RepairsAddReqVo reqVo) {
        repairsService.addRepairs(reqVo);
        return ResultUtil.success();
    }

    @DeleteMapping("/deleteRepairs")
    @ApiOperation(value = "删除报修记录")
    @SystemLog(description = "删除报修记录")
    public ResultData deleteRepairs(@Validated @RequestBody IdsReqVo reqVo) {
        repairsService.deleteRepairs(reqVo);
        return ResultUtil.success();
    }

    @GetMapping("/getRepairs")
    @ApiOperation(value = "获取单个报修记录")
    @SystemLog(description = "获取单个报修记录")
    public ResultData<RepairsRespVo> getRepairsById(@Validated IdReqVo reqVo) {
        return ResultUtil.success(repairsService.getRepairsById(reqVo));
    }

    @PutMapping("/updateRepairs")
    @ApiOperation(value = "修改保修记录")
    @SystemLog(description = "修改保修记录")
    public ResultData updateRepairs(@Validated @RequestBody IdAndStatusReqVo reqVo) {
        repairsService.updateRepairs(reqVo);
        return ResultUtil.success();
    }

    @GetMapping("/repairsPage")
    @ApiOperation(value = "报修记录分页")
    @SystemLog(description = "报修记录分页")
    public ResultData<Page<RepairsRespVo>> repairsPage(@Validated RepairsPageReqVo reqVo) {
        return ResultUtil.success(repairsService.repairsPage(reqVo));
    }

}
